<?php
namespace Admin\Controller;
use Think\Controller;
class BrandController extends CommenController {
    public function add(){
if(IS_POST){
        //D ==NEW 实例化
      $_POST['logo']=$this->upload();
     $id=$this->Model->add(I('post.'));

 // print_r($id);die;
        if ($id) {
         $this->success('操作完成',U('Admin/brand/lists'),1);
        }else{
        $this->error('操作失败','',2);
             }


      }
      $this->display();
    }



   public function lists()
    {

    import("ORG.Util.Page");// 导入分页类
    $count    = $this->Model->count();// 查询满足要求的总记录数
    $Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
    $show   = $Page->show();// 分页显示输出

    $list = $this->Model->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

    $this->assign('page',$show);// 赋值分页输出
    $this->assign('brand',$list);
    $this->display(); // 输出模板
    }

Public function upload(){
// import('ORG.Net.UploadFile');
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize  = 3145728 ;// 设置附件d上传大小
$upload->exts   = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->savePath =  '';// 设置附件上传目录
$upload->autoSub = true;

$upload->subName = array('date','Ymd');
 $info=$upload->uploadOne($_FILES['logo']);
// print_r($info) ;die;
if(!$info) {// 上传错误提示错误信息
$this->error($upload->getError());
}else{// 上传成功 获取上传文件信息


return 'Uploads/'.$info['savepath'].$info['savename'];
 // echo 'Uploads/'.$info['savepath'].$info['savename'];die;
}

}

}
